package pnu.ssm.controller.manager;
import java.util.ArrayList;
import java.util.Iterator;

import pnu.ssm.model.stuff.Factory;

// Singleton Pattern
// Iterator Pattern
public class FactoryManager implements Iterable<Factory>{
	private ArrayList<Factory> factories;
	
	private static FactoryManager instance = new FactoryManager();
	private FactoryManager() {
		factories = new ArrayList<Factory>();
	}
	public static FactoryManager getInstance(){
		return instance;
	}
	
	public void init(){
		factories.clear();
	}
	
	public void addFactory(Factory f){
		factories.add(f);
	}
	
	public int getFactoryCount(){
		return factories.size();
	}
	
	public Factory getFactory(String factoryName){
		Iterator<Factory> it = iterator();
		while(it.hasNext()){
			Factory f = it.next();
			if(f.getName().equals(factoryName)){
				return f;
			}
		}
		return null;
	}
	
	@Override
	public Iterator<Factory> iterator() {
		return factories.iterator();
	}
}
